<%@page import="${entityPackage}.${model.upEntityFileName}"%>
<%@page import="cn.ysnk.clz.util.PagerUtil"%>
<%@page import="com.jfinal.plugin.activerecord.Page"%>
<%@page import="cn.ysnk.clz.util.dateUtil.DateUtil"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<%
PagerUtil pageList = (PagerUtil)request.getAttribute("page");
<#if model.hasKeywordsSearch> 
String keywords = (String)request.getAttribute("keywords");
</#if>
%>
</head>
<body>
	<div class="default-padding container-fluid">
		<div class="page-header">
		  <h3>管理您的${name}</h3>
		</div>
		<form  style="margin-bottom:10px;" action="<%=request.getContextPath()%>/commodity" method="post">
		<#if model.hasKeywordsSearch> 
		关键字：<input value="<%=keywords %>" type="text" style="width: 20%;display: inline;" class="form-control" id="keywords" name="keywords"/>
		<button type="button" onclick="admin${model.upBaseEntityName}go(1)"  class="btn btn-primary default-margin-bottom">查询</button>
		</#if>
		<button type="button" onclick="add${model.upBaseEntityName}()" class="btn btn-primary default-margin-bottom">新增${name}</button>
		</form>
		<table class="table table-bordered table-hover">
			<thead>
				<tr>
					<th>序号</th>
				<#list model.columns as column>
					<#if column.listColumn> 
					<th>${column.commont}</th>
					</#if>
				</#list>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
			<%
			int index = 1;
		    for(${model.upEntityFileName} ${model.baseEntityName}:(List<${model.upEntityFileName}>)pageList.getElements()){
		    %>
		    	<tr>
		    		<td><%=index++ %></td>
    		<#list model.columns as column>
				<#if column.listColumn> 
					<#if column.date>
					<td><%= DateUtil.DateToString(${model.baseEntityName}.get${column.upcolumnName}(),"yyyy-MM-dd") %></td>
					<#else>
					<td><%=${model.baseEntityName}.get${column.upcolumnName}()==null?"无数据":${model.baseEntityName}.get${column.upcolumnName}() %></td>
					</#if>
				</#if>
			</#list>
		    		<td>
		    			<button type="button" onclick="edit${model.upBaseEntityName}('<%=${model.baseEntityName}.getStr("id") %>')" class="btn btn-info">修改</button>
		    			<button type="button" onclick="delete${model.upBaseEntityName}('<%=${model.baseEntityName}.getStr("id") %>')" class="btn btn-warning">删除</button>
		    		</td>
		    	</tr>
		    <%
		    }
		    %>
			</tbody>
		</table>
		<%=
		pageList.toHTML("admin${model.upBaseEntityName}")
		%>
	</div>
	<script type="text/javascript">
	function admin${model.upBaseEntityName}go(reqPageNum){
		var pageCount=reqPageNum;
		if(pageCount==""){
			alert("请填写页数");
			return;
		}
		<#if model.hasKeywordsSearch> 
		var keywords = $("#keywords").val();
		refreshTab("${controllerUrl}?pageNumber="+reqPageNum+"&keywords="+encodeURI(encodeURI(keywords)));
		<#else>
		refreshTab("${controllerUrl}?pageNumber="+reqPageNum);
		</#if>
	}
	function delete${model.upBaseEntityName}(commodityId){
		var submit = function (v, h, f) {
		    if (v == 'ok')
		    	ajaxDataPost("${controllerUrl}/delete${model.upBaseEntityName}",{commodityId:commodityId},function(){refreshTab("${controllerUrl}");},function(){});
		    return true; //close
		};
		$.jBox.confirm("确定删除该${name}吗？", "提示", submit);
	}
	function add${model.upBaseEntityName}(){
		refreshTab('${controllerUrl}/edit${model.upBaseEntityName}');
	}
	function edit${model.upBaseEntityName}(commodityId){
		refreshTab('${controllerUrl}/edit${model.upBaseEntityName}?${model.baseEntityName}Id='+commodityId);
	}
	</script>
</body>
</html>